import { takeEvery, put, all, takeLatest } from 'redux-saga/effects'
import { FETCH_HOME_MULTIDATA } from './constants'
import axios from "axios";
import { changeBannersAction, changeRecommendsAction } from './actionCreators'

function* fetchHomeMultidata(action) {
  const res = yield axios.get("http://123.207.32.32:8000/home/multidata")
  // console.log(res);
  const banners = res.data.data.banner.list
  const recommend = res.data.data.recommend.list
  // yield put(changeBannersAction(banners))
  // yield put(changeRecommendsAction(recommend))
  yield all([
    yield put(changeBannersAction(banners)), yield put(changeRecommendsAction(recommend))
  ])
}


function* mySaga() {
  // takeLatest 一次只能监听一个对应的action,总执行最后一次
  // takeEvery每一个都执行
  yield takeLatest(FETCH_HOME_MULTIDATA, fetchHomeMultidata)
}





export default mySaga